import api from "../../../utils/api";
var roleId = localStorage.getItem("_roleId");
var marineCode = localStorage.getItem("_marineCode");
export default {
    data(){
      return{
        //设备文件树
        deviceData:[],
        deviceId:[],
        defaultProps: {
            children: 'children',
            label: 'nodeName'
        },
      }
    },
    mounted() {
        
        this.initDeviceTypeTree();
        //设备文件树
        this.getTreeList();
    },
    methods:{
        handleNodeClick(data){
            window.console.log(data);
        },
        todetail(){
            this.$router.push("/deviceDetail")
        },
        //
        async initDeviceTypeTree(){
            let data = {
                params:""
            }
            const res = await this.$axios._post(api.initDeviceTypeTree,data);
            if(res.data.success){
             //   window.console.log(res);
                this.forData(res.data.data);
            }
        },
        //循环设备树数据
        forData(res){
            let obj = res[0];
            obj.children = [];
            this.deviceData.push(obj);
            res.splice(0,1);
            orderData(this.deviceData);
            function orderData(newRes){
                for(let i=0;i<newRes.length;i++){
                    for(let j=0;j<res.length;j++){
                        if(newRes[i].nodeCode == res[j].parentCode){
                            var obj1 = res[j];
                            obj1.children = [];
                            newRes[i].children.push(obj1);
                            res.splice(j,1);
                            j--;
                        }
                    }
                    orderData(newRes[i].children);
                }
            }
          //  window.console.log(this.deviceData);
        },
        //获取设备类型树
        async getTreeList(){
            let data = {
                params:"roleId="+roleId+"&marineBoardCode="+marineCode
            }
            const res = await this.$axios._post(api.initDeviceTree,data);
            if(res.data.success){
                window.console.log(res);
            }
        }
    }
  }